# +----------------------------------------------------------------------
# | Pink [ A modern python web framework ]
# +----------------------------------------------------------------------
# | Copyright (c) 2023 http:#unnnnn.com All rights reserved.
# +----------------------------------------------------------------------
# | Author: chenjianhua <unnnnn@foxmail.com>
# +----------------------------------------------------------------------

import os

from .. import Middleware
from ...facades import View
from ...utils.location import base_path


class MaintenanceModeMiddleware(Middleware):
    def before(self, request, response):
        down = os.path.exists(base_path(".down"))
        if down is True:
            return response.view(View.render("maintenance"), status=503)
        return request

    def after(self, request, _):
        return request
